package com.ymatou.iapi.liveseller.testcase;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.ymatou.iapi.liveseller.parameter.LiveProductListBean;
import com.ymatou.iapi.liveseller.service.LiveProductListCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productquery.parameter.ApplyActivityDto;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.business.service.ProductPriceCallService;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.mongo.jproduct.ActivityProductsWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;
/**
*直播商品列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_LiveProductList{
	private static LiveProductListBean liveproductlistBean;
	private static LiveProductListCall liveproductlistCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直播商品列表");
	}

	@Before
	public void caseUp() {
		liveproductlistBean=new LiveProductListBean();
		liveproductlistCall=new LiveProductListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(liveproductlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	//直播商品列表逻辑业务验证优先
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_LiveProductList_001() {
		Logger.start(true,"查询可售直播商品列表成功");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			List<String> ProductIdList = new ArrayList<>();
			int count = 10;
			for (int i = 0; i < count; i++) {
				String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
				
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			Collections.shuffle(ProductIdList);
			LiveRoomCallService.SortLiveProduct(createlive.getId(), createlive.getUserId(), ProductIdList);
			
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(10, liveproductlistCall.getProductList().size(), "验证有1个商品");
			JsonArray plist = liveproductlistCall.getProductList();
			for (int i=0;i<plist.size();i++) {
				Logger.verifyEquals(ProductIdList.get(i),plist.get(i).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
				Logger.verifyEquals("0",plist.get(i).getAsJsonObject().get("PublishType").getAsString(),"验证PublishType");
			}
			
			Logger.verifyEquals(10, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_LiveProductList_002() {
		Logger.start(true,"不输入liveid失败");
		try {
			liveproductlistBean.setUserId(1);
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("400", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("直播Id不能为空", liveproductlistCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_LiveProductList_003() {
		Logger.start(true,"不输入Userid失败");
		try {
			liveproductlistBean.setLiveId(1);
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("201", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播不存在", liveproductlistCall.getString("Msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_004() {
		Logger.start(true,"liveid和userid不匹配失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId()+1);
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("201", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("不合法", liveproductlistCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_LiveProductList_005() {
		Logger.start(true,"不输入TabIndex失败");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
//			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("400", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("参数错误", liveproductlistCall.getString("Msg"), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_006() {
		Logger.start(true,"查询售罄直播商品列表成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid = ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 1);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			ProductManagerCallServiceV2.updateAllStockNumAs0(uinfo.getUserId(), pid);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(2);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(1, liveproductlistCall.getProductList().size(), "验证有1个商品");
			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(1, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_007() {
		Logger.start(true,"查询暂停销售直播商品列表成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid = ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 1);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SuspendLiveProduct(createlive.getId(), pid);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(3);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(1, liveproductlistCall.getProductList().size(), "验证有1个商品");
			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(1, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_008() {
		Logger.start(true,"模糊搜索商品成功");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistBean.setProductName("自动化测试");
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(1, liveproductlistCall.getProductList().size(), "验证有1个商品");
			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(1, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_009() {
		Logger.start(true,"status9直播推流结束查询商品成功");
		try {
			//正常结束的时候商品列表全部变成暂停销售状态
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			new LiveRoomWapper().updateLiveRoomPushStatus(createlive.getId(), 9);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistBean.setProductName("自动化测试");
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyEquals(1, liveproductlistCall.getProductList().size(), "验证有1个商品");
			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(1, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_010() {
		Logger.start(true,"未推流status7系统关闭查询商品失败不返回商品");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomCallService.SysCloseLive(createlive.getId());
			
			LiveRoom room = new LiveRoomWapper().selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(7, room.getLiveStatus(), "验证状态");
			
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistBean.setProductName("自动化测试");
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(0, liveproductlistCall.getProductList().size(), "验证有0个商品");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_011() {
		Logger.start(true,"status8未推流关闭直播查询商品失败不返回商品");
		try {
			//异常关闭结束的时候商品列表全部移除
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
//			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomCallService.AutoCloseLiveRoomByUserId(createlive.getUserId());
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(3);
			liveproductlistBean.setProductName("自动化测试");
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(0, liveproductlistCall.getProductList().size(), "验证有1个商品");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//运营接口尚未完成
	public void Tc_LiveProductList_012() {
		Logger.start(true,"status10运营关闭直播查询商品失败不返回商品");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_013() {
		Logger.start(true,"推过流status7系统关闭查询商品返回暂停销售");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			LiveRoomCallService.SysCloseLive(createlive.getId());
			LiveRoomWapper LiveRoomWapper= new LiveRoomWapper();
			LiveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 7);
			LiveRoom room = LiveRoomWapper.selectLiveRoomById(createlive.getId());
			Logger.verifyEquals(7, room.getLiveStatus(), "验证状态");
			
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistBean.setProductName("自动化测试");
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			//1215需求不下架
			Logger.verifyEquals(1, liveproductlistCall.getProductList().size(), "验证有商品");
			Logger.verifyEquals(1, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_LiveProductList_014() {
		Logger.start(true,"上线后查询可售直播商品列表成功,顺序正确");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			List<String> ProductIdList = new ArrayList<>();
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			int count = 10;
			
			for (int i = 0; i < count; i++) {
				AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(uinfo.getUserId());
//				addpro.getProduct().setLiveRoomId(createlive.getId());
				String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			Collections.shuffle(ProductIdList);
			LiveRoomCallService.SortLiveProduct(createlive.getId(), createlive.getUserId(), ProductIdList);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(10, liveproductlistCall.getProductList().size(), "验证有1个商品");
			JsonArray plist = liveproductlistCall.getProductList();
			for (int i=0;i<plist.size();i++) {
				Logger.verifyEquals(ProductIdList.get(i),plist.get(i).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
				Logger.verifyEquals(false,plist.get(i).getAsJsonObject().get("FastPublishProduct").getAsBoolean(),"验证商品FastPublishProduct");
			}
			
			Logger.verifyEquals(10, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_LiveProductList_015() {
		Logger.start(true,"查询快速发布直播商品列表成功FastPublishProduct=true");
		try {
			
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			List<String> ProductIdList = new ArrayList<>();
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			int count = 10;
			for (int i = 0; i < count; i++) {
				AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(uinfo.getUserId());
				addpro.getProduct().setLiveRoomId(createlive.getId());
				String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
//			Collections.shuffle(ProductIdList);
//			LiveRoomCallService.SortLiveProduct(createlive.getId(), createlive.getUserId(), ProductIdList);
			Thread.sleep(5000);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(10, liveproductlistCall.getProductList().size(), "验证有10个商品");
			JsonArray plist = liveproductlistCall.getProductList();
			for (int i=0;i<plist.size();i++) {
//				Logger.verifyEquals(ProductIdList.get(i),plist.get(i).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
				Logger.verifyEquals(true,plist.get(i).getAsJsonObject().get("FastPublishProduct").getAsBoolean(),"验证商品FastPublishProduct");
			}
			
			Logger.verifyEquals(10, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_016() {
		Logger.start(true,"查询售罄直播商品列表成功-不传ListType默认0代表秒杀选择商品-只看库存不看活动库存");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(uinfo.getUserId());
			String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
			Logger.comment("创建商品：" + pid);
			//获取规格
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(pid).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
			Logger.comment("创建活动：" + activityId);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(pid, uinfo.getUserId(),catalogs,activityId, 100,"10");
	        ProductManagerCallServiceV2.approveProductInActivityV2(pid,aids1.get(0),true);
	        Date starttime=YMTDateUtil.getBeforeOrNextSecond(new Date(),-10);
	        Logger.debug("starttime:"+starttime);
	        new ActivityProductsWapper().updateStartTimeByInAid(Integer.valueOf(aids1.get(0)),starttime);
	        ProductManagerCallServiceV2.updateProductTimeStamp(pid);
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			ProductManagerCallServiceV2.updateAllStockNumAs0(uinfo.getUserId(), pid);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(2);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			//售罄
			Logger.verifyEquals(1, liveproductlistCall.getProductList().size(), "验证有1个商品");
//			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(1, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
			//可售
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyEquals(0, liveproductlistCall.getProductList().size(), "验证有1个商品");
//			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(1, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_017() {
		Logger.start(true,"查询售罄直播商品列表成功-ListType1代表普通商品-库存和活动库存都要看");
		try {
			//listtype=1 普通场景- 有活动库存没普通库存也是在售
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(uinfo.getUserId());
			String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
			Logger.comment("创建商品：" + pid);
			//获取规格
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(pid).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
			Logger.comment("创建活动：" + activityId);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(pid, uinfo.getUserId(),catalogs,activityId, 100,"10");
	        ProductManagerCallServiceV2.approveProductInActivityV2(pid,aids1.get(0),true);
	        Date starttime=YMTDateUtil.getBeforeOrNextSecond(new Date(),-10);
	        Logger.debug("starttime:"+starttime);
	        new ActivityProductsWapper().updateStartTimeByInAid(Integer.valueOf(aids1.get(0)),starttime);
	        ProductManagerCallServiceV2.updateProductTimeStamp(pid);
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			ProductManagerCallServiceV2.updateAllStockNumAs0(uinfo.getUserId(), pid);
			liveproductlistBean.setListType(1);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(2);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			//售罄
			Logger.verifyEquals(0, liveproductlistCall.getProductList().size(), "验证有0个商品");
//			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(1, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
			//可售
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyEquals(1, liveproductlistCall.getProductList().size(), "验证有1个商品");
			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(1, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_018() {
		Logger.start(true,"查询售罄直播商品列表成功-ListType2代表秒杀商品-只看库存不看活动库存");
		try {
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(uinfo.getUserId());
			String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
			Logger.comment("创建商品：" + pid);
			//获取规格
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(pid).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
			Logger.comment("创建活动：" + activityId);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(pid, uinfo.getUserId(),catalogs,activityId, 100,"10");
	        ProductManagerCallServiceV2.approveProductInActivityV2(pid,aids1.get(0),true);
	        Date starttime=YMTDateUtil.getBeforeOrNextSecond(new Date(),-10);
	        Logger.debug("starttime:"+starttime);
	        new ActivityProductsWapper().updateStartTimeByInAid(Integer.valueOf(aids1.get(0)),starttime);
	        ProductManagerCallServiceV2.updateProductTimeStamp(pid);
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			ProductManagerCallServiceV2.updateAllStockNumAs0(uinfo.getUserId(), pid);
			liveproductlistBean.setListType(2);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(2);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			//售罄
			Logger.verifyEquals(0, liveproductlistCall.getProductList().size(), "验证有0个商品");
			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(1, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
			//可售
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyEquals(0, liveproductlistCall.getProductList().size(), "验证有1个商品");
//			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(1, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_019() {
		Logger.start(true,"查询售罄直播商品列表成功-ListType0=2兼容代表秒杀商品-只看库存不看活动库存");
		try {
			
			List<Userinfo> list =new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(uinfo.getUserId());
			String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
			Logger.comment("创建商品：" + pid);
			//获取规格
			
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(pid).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Integer activityId = ProductManagerCallServiceV2.createNoIsolationActivityInProcessV2();
			Logger.comment("创建活动：" + activityId);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			List<String> aids1 = ProductManagerCallServiceV2.ApplyActivity(pid, uinfo.getUserId(),catalogs,activityId, 100,"10");
	        ProductManagerCallServiceV2.approveProductInActivityV2(pid,aids1.get(0),true);
	        Date starttime=YMTDateUtil.getBeforeOrNextSecond(new Date(),-10);
	        Logger.debug("starttime:"+starttime);
	        new ActivityProductsWapper().updateStartTimeByInAid(Integer.valueOf(aids1.get(0)),starttime);
	        ProductManagerCallServiceV2.updateProductTimeStamp(pid);
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			ProductManagerCallServiceV2.updateAllStockNumAs0(uinfo.getUserId(), pid);
			liveproductlistBean.setListType(0);
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(2);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			//售罄
			Logger.verifyEquals(0, liveproductlistCall.getProductList().size(), "验证有0个商品");
			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(1, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
			//可售
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyEquals(0, liveproductlistCall.getProductList().size(), "验证有1个商品");
//			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
			Logger.verifyEquals(0, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(1, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_LiveProductList_020() {
		Logger.start(true,"直播间商品查询待讲解次数");
		try {
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String pid = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(sellerId));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), pid);
			LiveRoomCallService.SellerLiveOnline(createlive.getId(), createlive.getUserId());
			int AskNum=10;
			//求讲解
			for (int i = 1; i < AskNum+1; i++) {
				LiveRoomCallService.AskProductVideo(createlive.getId(), pid, i);
			}
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			Logger.verifyEquals(AskNum,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("AskNum").getAsInt(),"验证求讲解次数");
			Logger.verifyEquals(pid,liveproductlistCall.getProductList().get(0).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_LiveProductList_021() {
		Logger.start(true,"查询可售直播商品列表成功-publishtype=2");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			List<String> ProductIdList = new ArrayList<>();
			int count = 1;
			for (int i = 0; i < count; i++) {
				AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(uinfo.getUserId());
				addpro.getProduct().setPublishType(2);
				String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			LiveRoomCallService.AddProductsToLive(createlive.getId(), createlive.getUserId(), ProductIdList);
			Collections.shuffle(ProductIdList);
			LiveRoomCallService.SortLiveProduct(createlive.getId(), createlive.getUserId(), ProductIdList);
			
			liveproductlistBean.setLiveId(createlive.getId());
			liveproductlistBean.setUserId(createlive.getUserId());
			liveproductlistBean.setTabIndex(1);
			liveproductlistCall.setData(liveproductlistBean);
			liveproductlistCall.callService();			
			Logger.verifyEquals("200", liveproductlistCall.getString("Code"), "验证Code");
			
			Logger.verifyEquals(1, liveproductlistCall.getProductList().size(), "验证有1个商品");
			JsonArray plist = liveproductlistCall.getProductList();
			for (int i=0;i<plist.size();i++) {
				Logger.verifyEquals(ProductIdList.get(i),plist.get(i).getAsJsonObject().get("ProductId").getAsString(),"验证商品id");
				Logger.verifyEquals("2",plist.get(i).getAsJsonObject().get("PublishType").getAsString(),"验证PublishType");
			}
			
			Logger.verifyEquals(1, liveproductlistCall.getOnsaleCount(), "验证getOnsaleCount");
			Logger.verifyEquals(0, liveproductlistCall.getSuspendCount(), "验证SuspendCount");
			Logger.verifyEquals(0, liveproductlistCall.getSoldOutCount(), "验证SoldOutCount");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}